/**
 * 获得搜索参数
 * @param params
 * @returns {Object}
 */
function getSearchParams(params) {
    var searchParams = new Object();
    if (params != undefined) {
        searchParams = params;
    }
    $('.SearchForm').each(function() {
        var param = $(this).val().trim();
        var val = $("input:checkbox[name='sex']:selected").val();
        if (val == 1) {
            searchParams['sex'] = 1;
        } else if (val == 2) {
            searchParams['sex'] = 2;
        }
        if (param == undefined)
            param = '';
        searchParams[$(this).attr('name')] = param;
    });
    return searchParams;
}
//清空搜索条件
$("#Reset").click(function() {
    $('.SearchForm').val('');
    $("input:radio[name='sex']").removeAttr('checked');
});

/**
 * 页面自加载
 */
$(function() {
    // $('#student_createtime').datepicker({
    //     format: "yyyy-mm-dd",
    //     todayBtn: "linked",
    //     autoclose: true,
    //     todayHighlight: true,
    //     clearBtn: true
    // });

    var cellwidth = ($(".box-content.table-responsive").width() - 55) / 11;
    var psval = $('#datatable_studentinfo').attr('data-size');
    if (psval == undefined || psval == "") {
        psval = 10;
    }
    /**
     * easyui 生成表格数据
     */
    $('#datatable_studentinfo').datagrid({
        singleSelect: true, //允许选择多行
        striped: true,
        idField: 'id',
        remoteSort: false,
        collapsible: true,
        fit: false,
        url: 'admin/FeedBack/getFeedBackData', //数据源路径
        loadMsg: '请等待数据载入....',
        pagination: true,
        rownumbers: true,
        fitColumns: true,
        pageSize: psval,
        pageList: [psval, psval * 2, psval * 3, psval * 4, psval * 5],
        columns: [[{
            field: 'user_username',
            title: '反馈人',
            align: 'center',
            width: cellwidth,
            sortable: true
        }, {
            field: 'fb_name',
            title: '反馈类型',
            align: 'center',
            width: cellwidth,
            sortable: true,
            formatter: function (value) {
                return value.substring(0,6)+'...';
            }
        }, {
            field: 'feedback_content',
            title: '反馈内容',
            align: 'center',
            width: cellwidth,
            sortable: true,
            formatter: function (value) {
                return value.substring(0,6)+'...';
            }
        }, {
            field: 'feedback_weixin',
            title: '微信/QQ',
            align: 'center',
            width: cellwidth,
            sortable: true
        }, {
            field: 'feedback_status',
            title: '状态',
            align: 'center',
            width: cellwidth,
            sortable: true,
            formatter: function (value) {
                if (value == 1) {
                    return "<span style='color:red;font-weight: bold'>未处理</span>";
                }
                if (value == 2) {
                    return "<span style='color:green;font-weight: bold'>已处理</span>";
                }
            }
        }, {
            field: 'feedback_id',
            title: '操作',
            align: 'center',
            width: cellwidth,
            sortable: true,
            formatter: function (value, row, index) {
                var html = '';
                if (row.feedback_status == 1) {
                    html = "<a onclick='TyInfo(this);' style='color:#F17A02;margin-left:5px;font-weight: bold' name='" + row.feedback_id + "' href='JavaScript:;'>处理</a>&nbsp;&nbsp;&nbsp;";
                } else {
                    html = "<a onclick='QyInfo(this);' style='margin-left:5px;font-weight: bold' name='" + row.feedback_id + "' href='JavaScript:;'>修改处理结果</a>&nbsp;&nbsp;&nbsp;";
                }
                return html;
            }
        }]],
        onBeforeLoad: function (param) {
            param = getSearchParams(param);
        },
    });
    /*搜索*/
    $('#Search').click(function () {
        $('#datatable_studentinfo').datagrid('reload');
    })


    /**
     * 删除
     */
    $('#del').click(function() {
        var row = $('#datatable_studentinfo').datagrid('getSelections');
        if (row.length < 1) {
            $.TeachDialog({
                content: '请选择一行数据进行修改！',
            });
            return;
        }
        if (row.length > 1) {
            $.TeachDialog({
                content: '只能选择一行进行修改！',
            });
            return;
        }
        $.TeachDialog({
            content: "确认删除此反馈？",
            showCloseButton: true,
            showCloseButtonName: '取消',
            otherButtons: ['确认'],
            otherButtonStyles: ['btn-danger'],
            clickButton: function(sender, modal, index) {
                modal.modal('hide');
                $.ajax({
                    url: 'Admin/Feedback/deleteFeedback', //form action
                    dataType: 'JSON', //返回体类型
                    type: 'POST', // form type
                    data: "id=" + row[0].feedback_id,
                    success: function(data) {
                        if (data.status == 1) {
                            layer.msg(data.msg,{icon:6,time:2000});
                            $('#datatable_studentinfo').datagrid('reload');
                            $('#datatable_studentinfo').datagrid('uncheckAll');
                        } else {
                            layer.msg(data.msg,{icon:5,time:2000});
                        }
                    },
                    error: function() {
                        layer.msg("删除失败!",{icon:5,time:2000});
                    }
                });
            }
        })
    });


    /**
     * 查看详情
     */
    $("#look").click(function() {
        var row = $('#datatable_studentinfo').datagrid('getSelections');
        if (row.length < 1) {
            $.TeachDialog({
                content: '请选择一个用户进行查看！'
            });
            return;
        }
        if (row.length > 1) {
            $.TeachDialog({
                content: '请选择一个用户进行查看！',
            });
            return;
        }
        //获得修改框内容
        var content = "";
        $.ajax({
            url:"admin/Feedback/lookFeedback",
            data:"id=" + row[0].feedback_id,
            type:'POST',
            dataType:'HTML',
            success:function(returndata){
                content = returndata;
                $.TeachDialog({
                    modalId: null,
                    animation: null,
//                        largeSize:true,
                    title: "<h2>反馈详情</h2>",
                    content: content,
                    showCloseButton: true,
                    showCloseButtonName: '关闭',
                    CloseButtonAddFunc: function () {
                    }
                });
            },
            error:function(){
                alert('数据返回出错，无伤大雅，请继续');
            }
        });
    });


    /**
     * 添加处理结果
     */
    $("#add").click(function() {

    });

})